import http from '@/api/index';
import { useTranslateLangStore } from '@/stores/translateLang';

enum API {
    LOGIN = '/translate/login/loginV2', //登录
    REFRESH_TOKEN = '/translate/login/refreshAppToken', //token刷新
    GET_USER_INFO = '/translate/login/getUserInfo', //获取用户信息
    GET_LOGIN_VERIFY_IMG = '/translate/login/getImageCaptcha', //获取图形验证码
    ACCOUNT_REGISTER = '/translate/login/registerAppAccount', //账号注册
    ACCOUNT_LOGIN = '/translate/login/appLogin', //账号登录
}

//通过code登陆
export function login(code: string) {
    return http.get({
        url: API.LOGIN,
        data: {
            code: code,
            modelType: useTranslateLangStore().targetLang
        },
        errToast: false
    });
}

//刷新token
export function refreshAppToken() {
    return http.get({
        url: API.REFRESH_TOKEN,
        errToast: false
    });
}


//获取用户信息
export function getUserInfo() {
    return http.get({
        url: API.GET_USER_INFO
    });
}

//获取图形验证码
export function getLoginVerifyImg() {
    return http.get({
        url: API.GET_LOGIN_VERIFY_IMG,
        catchError: false
    });
}

//账号注册
export function accountRegister(data: any) {
    return http.post({
        url: API.ACCOUNT_REGISTER,
        data,
    });
}

//账号登录
export function accountLogin(data: any) {
    return http.post({
        url: API.ACCOUNT_LOGIN,
        data,
    });
}


